<?php
/**
 * Created by PhpStorm.
 * User: junyv
 * Date: 2016/9/25
 * Time: 9:42
 */

namespace app\manage\controller;


class LinkmenuCate extends Base
{
    private $mod;
    protected $beforeActionList = [
      'beforeIndex' => ['only' => 'index']
    ];
    public function _initialize(){
        parent::_initialize();
        $this->mod = model('linkmenu_cate');
    }
    public function beforeindex() {
        $big_menu = array(
            'title' => '增加分类',
            'iframe' => url('LinkmenuCate/add'),
            'id' => 'add',
            'width' => '400',
            'height' => '90'
        );
        $this->_ajaxedit = 1;
        $this->_data = array(
            'addchildmenu'    => array(
                'c' => 'Linkmenu',
                'a' => 'add',
                'str'    => '<a data-height="400" data-width="500" data-id="add" data-uri="%s" data-title="添加 - 添加子菜单" class="J_showdialog" href="javascript:;">添加子菜单</a>',
                'param' => array('menu_id'=>'@id@'),
                'isajax' => 1,
                'replace'=> ''
            ),
            'menulist'    => array(
                'c' => 'Linkmenu',
                'a' => 'index',
                'str'    => '<a href="%s">子菜单管理</a>',
                'param' => array('menu_id'=>'@id@'),
                'isajax' => 0,
                'replace'=> ''
            ),
        );
        $this->assign('big_menu', $big_menu);
    }
    public function delete(){
        //判断是否有下级菜单存在  存在则不能删除
        \app\manage\model\LinkmenuCate::event('before_delete',function($obj){
            $id = $obj->id;
            //是否有下级菜单
            $child = model('linkmenu')->where('menuid',$id)->count();

            if(!empty($child)){
                return false;
            }
            return true;
        });
        parent::delete();
    }
}